import { prisma } from '@/lib/prisma/client'
import { NextResponse } from 'next/server'

export async function POST(
  request: Request,
  { params }: { params: { id: string } }
) {
  try {
    const { id } = await Promise.resolve(params)
    
    const scene = await prisma.scene.findUnique({
      where: { id },
      include: {
        actions: true,
        devices: true
      }
    })

    if (!scene) {
      return NextResponse.json(
        { error: '场景不存在' },
        { status: 404 }
      )
    }

    // 简单执行场景动作，移除所有 socket 相关代码
    await new Promise(resolve => setTimeout(resolve, 1000))
    
    return NextResponse.json({ 
      success: true,
      message: `场景「${scene.name}」执行成功`,
      scene: {
        id: scene.id,
        name: scene.name
      }
    })
  } catch (error) {
    console.error('执行场景失败:', error)
    return NextResponse.json(
      { error: '执行场景失败' },
      { status: 500 }
    )
  }
} 